﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.IO;
using System.Diagnostics;
using System.Windows;
using Samurai.Infrastructure;

namespace Samurai.Client
{
    public class ExitCommand : ICommand
    {
        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            Application.Current.Shutdown();
        }
    }

    public class OpenDirectoryCommand : ICommand
    {
        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            if (parameter != null)
            {
                var candidateMovie = (ILocatable)parameter;

                var directoryLocation = candidateMovie.Path;

                if (Directory.Exists(directoryLocation))
                    Process.Start(directoryLocation);
                else
                    MessageBox.Show(string.Format("{0}{1}Not Found", directoryLocation, Environment.NewLine));
            }
        }

        private OpenDirectoryCommand()
        {

        }

        private static OpenDirectoryCommand _instance;
        public static OpenDirectoryCommand Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new OpenDirectoryCommand();
                return _instance;
            }
        }
    }
}
